package com.BahavioralPartterns.observer.push;

import java.util.ArrayList;

public class ShopSubject implements Subject {
	private String goodsName;
	private double oldPrice,newPrice;
	private ArrayList<Observer> customerList;
	public ShopSubject(){
		this.customerList=new ArrayList<Observer>();
	}
	public void addObserver(Observer o){
		if(!customerList.contains(o))
			this.customerList.add(o);
	}
	public void deleteObserver(Observer o){
		if(customerList.contains(o))
			this.customerList.remove(o);
	}
	public void notifyObservers(){
		for(int i=0;i<this.customerList.size();++i){
			Observer o=this.customerList.get(i);
			o.update();
		}
	}
	public void setDiscountgoods(String goodName,double oldP,double newP){
		this.goodsName=goodName;
		this.oldPrice=oldP;
		this.newPrice=newP;
		notifyObservers();
	}
	public String getGoodsName() {
		return goodsName;
	}
	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}
	public double getOldPrice() {
		return oldPrice;
	}
	public void setOldPrice(double oldPrice) {
		this.oldPrice = oldPrice;
	}
	public double getNewPrice() {
		return newPrice;
	}
	public void setNewPrice(double newPrice) {
		this.newPrice = newPrice;
	}
	public ArrayList<Observer> getCustomerList() {
		return customerList;
	}
	public void setCustomerList(ArrayList<Observer> customerList) {
		this.customerList = customerList;
	}
}
